/**
 * Copyright (c) 2012 Nokia Corporation.
 * All rights reserved.
 *
 * For the applicable distribution terms see the license text file included in
 * the distribution.
 */

#include <QtCore/QObject>
#include <QtGui/QApplication>
#include <QtDeclarative/QDeclarativeContext>
#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeView>


#include <socialconnectplugin.h>

#include "networkaccess.h"
#include "placeslistmodel.h"
#include "routemanager.h"
#include "settings.h"

#ifdef HARMATTAN_BOOSTER
#include <MDeclarativeCache>
#endif

Q_DECL_EXPORT int main(int argc, char *argv[])
{
#ifdef HARMATTAN_BOOSTER
    QScopedPointer<QApplication> app(MDeclarativeCache::qApplication(argc, argv));
#else
    QScopedPointer<QApplication> app(new QApplication(argc, argv));
#endif

    // Construct and register the Facebook Connect plug-in.
    SocialConnectPlugin socialConnectPlugin;
    socialConnectPlugin.registerTypes("SocialConnectPlugin");

    QDeclarativeView view;
    view.setResizeMode(QDeclarativeView::SizeRootObjectToView);
    QObject::connect(view.engine(), SIGNAL(quit()), app.data(), SLOT(quit()));

#ifdef Q_OS_SYMBIAN
    view.setAttribute(Qt::WA_NoSystemBackground);
#endif

    // Use custom QNetworkAccessManager for using different user agent with login.
    NetworkAccessManagerFactory factory;
    view.engine()->setNetworkAccessManagerFactory(&factory);
    PlacesListModel placesListModel;
    view.rootContext()->setContextProperty("placesListModel", &placesListModel);
    RouteManager routeManager;
    view.rootContext()->setContextProperty("routeManager", &routeManager);
    Settings settings;
    view.rootContext()->setContextProperty("settings", &settings);

#ifdef Q_WS_SIMULATOR
    view.rootContext()->setContextProperty("isSimulator", true);
#else
    view.rootContext()->setContextProperty("isSimulator", false);
#endif

#ifdef Q_WS_HARMATTAN
    view.setSource(QUrl("qrc:/main.qml"));
#else
    view.setSource(QUrl("qrc:/MainLoader.qml"));
#endif

    view.showFullScreen();
    return app->exec();
}
